package sz.com.postoffice.jxyzwgcase.controller;

import com.sun.istack.NotNull;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import sz.com.postoffice.jxyzwgcase.core.TableDataInfo;
import sz.com.postoffice.jxyzwgcase.pojo.CustomerModel;
import sz.com.postoffice.jxyzwgcase.pojo.Enterprise;
import sz.com.postoffice.jxyzwgcase.pojo.EnterpriseCustomer;
import sz.com.postoffice.jxyzwgcase.pojo.ResourceCustomerRelation;
import sz.com.postoffice.jxyzwgcase.service.CustomerModelService;
import sz.com.postoffice.jxyzwgcase.service.EnterpriseCustomerService;
import sz.com.postoffice.jxyzwgcase.service.ResourceMarketService;

import javax.annotation.Resource;

/**
 * @ClassName EnterpriseCustomerController
 * @Deacription
 * @Author jmx
 * @Date 2020/11/21 19:52
 * @Version 1.0
 **/
@Api(value = "企业客户基础信息", tags = "{企业客户基础信息API}")
@RestController
@Slf4j
@RequestMapping(value = "/resource")
public class EnterpriseCustomerController {
    @Resource
    private EnterpriseCustomerService enterpriseCustomerService;

    @ApiOperation(value = "修改企业", notes = "修改企业")
    @RequestMapping(value = "/enterprises", method = RequestMethod.PUT)
    public boolean update(@RequestBody EnterpriseCustomer enterpriseCustomer) {
        System.out.println("开始修改...");
        //只能修改关联关系
        ResourceCustomerRelation resourceCustomerRelation = new ResourceCustomerRelation();
        resourceCustomerRelation.setId(enterpriseCustomer.getRelationId());
        resourceCustomerRelation.setType(enterpriseCustomer.getResourceType());
        resourceCustomerRelation.setCustomerCode(enterpriseCustomer.getCode());
        resourceCustomerRelation.setResourceCode(enterpriseCustomer.getResourceCode());
        return enterpriseCustomerService.updateRelation(resourceCustomerRelation);
    }

    @ApiOperation(value = "查询商企列表", notes = "查询商企列表")
    @RequestMapping(value = "/enterprises", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "pageNum", value = "当前页", dataType = "int", paramType = "path", required = true)
    })
    public TableDataInfo findByInfo(EnterpriseCustomer enterpriseCustomer) {
        return enterpriseCustomerService.findByListEntity(enterpriseCustomer);
    }

    @ApiOperation(value = "查询商企详情", notes = "查询商企详情")
    @RequestMapping(value = "/enterprises/{id}", method = RequestMethod.GET)
    public EnterpriseCustomer findById(@PathVariable("id") @NotNull @ApiParam(name="商企id",value="path传入",required=true) Integer id) {
        return enterpriseCustomerService.findByPrimaryKey(id);
    }

}
